package com.corot.codoc.bean;

import com.corot.core.model.entity.BaseEntity;
import org.hibernate.annotations.ForeignKey;
import org.hibernate.annotations.NotFound;
import org.hibernate.annotations.NotFoundAction;

import javax.persistence.*;

/**
 * 段落 章节
 *
 * @author leesir
 */
@Entity
public class Segment extends BaseData {
    private Integer id;
    private String name;
    private Segment parent;
    private Integer sort; // 同级下的排序 从小到大排
    private EBook eBook;

    @Id
    @GeneratedValue(strategy = GenerationType.AUTO)
    public Integer getId() {
        return id;
    }

    public void setId(Integer id) {
        this.id = id;
    }

    public String getName() {
        return name;
    }

    public void setName(String name) {
        this.name = name;
    }
    @ManyToOne
    @JoinColumn(name = "parent_id")
    @ForeignKey(name="null")
    @NotFound(action = NotFoundAction.IGNORE)
    public Segment getParent() {
        return parent;
    }

    public void setParent(Segment parent) {
        this.parent = parent;
    }

    @ManyToOne
    @JoinColumn(name = "e_book_id")
    @ForeignKey(name="null")
    @NotFound(action = NotFoundAction.IGNORE)
    public EBook geteBook() {
        return eBook;
    }

    public void seteBook(EBook eBook) {
        this.eBook = eBook;
    }

    public Integer getSort() {
        return sort;
    }

    public void setSort(Integer sort) {
        this.sort = sort;
    }
}
